{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WBK_EQ2mjh1h"
   },
   "source": [
    "# Set fold number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "ILQh5fsg8g_w"
   },
   "outputs": [],
   "source": [
    "index = 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "tjVbXSt9jmwU"
   },
   "source": [
    "# Training"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "YDCc1hVhqKP7"
   },
   "outputs": [],
   "source": [
    "import shutil\n",
    "\n",
    "with open(f\"{index}/val.txt\") as f:\n",
    "    for line in f:\n",
    "        file = \"train/\" + line.strip()\n",
    "        shutil.copyfile(file, f\"{index}/images/val/\" + line.strip())\n",
    "with open(f\"{index}/train.txt\") as f:\n",
    "    for line in f:\n",
    "        file = \"train/\" + line.strip()\n",
    "        shutil.copyfile(file, f\"{index}/images/train/\" + line.strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "5f9mXPEd8IRh"
   },
   "outputs": [],
   "source": [
    "import yaml\n",
    "\n",
    "result = {\n",
    "    \"train\": f\"../{str(index)}/images/train\",\n",
    "    \"val\": f\"../{str(index)}/images/val\",\n",
    "    \"nc\": 1,\n",
    "    \"names\": [\"wheat\"],\n",
    "}\n",
    "with open(\"GWC_YOLOv5/data/custom.yaml\", \"w\") as f:\n",
    "    dump = yaml.dump(result, default_flow_style=False)\n",
    "    f.write(dump)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "t8r3s6gN6Myq"
   },
   "outputs": [],
   "source": [
    "!cd GWC_YOLOv5 && python train.py --name 4fold{index} --img 800 --batch 8 --epochs 35 --data custom.yaml --weights yolov5x.pt --cache-images"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "collapsed_sections": [],
   "machine_shape": "hm",
   "name": "Copy of YOLOv5_czz.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
